﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BussinessObject;
using Class_Entity;
using System.Data;
using System.Data.SqlClient;

public partial class WebApplication_RegisterForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["RoleCode"] != null)
        {
            Response.Redirect("Default.aspx");
        }
    }
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        
        BOUsers bo = new BOUsers();
        Users us = new Users();

        us.Username = txtUsername.Text.Trim();
        us.Password = txtPassword.Text.Trim();
        us.Fullname = txtFullname.Text.TrimStart();
        us.Email = txtEmail.Text.Trim();
        us.Address = txtAddress.Text.TrimStart();
        us.Tel = txtTel.Text.Trim();

        if (Session["a"]==null)
        {
            bo.Add_Users(us);
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Register Successfully ..." + "');window.location.href='Login.aspx';</script>");
        }
    }
    protected void txtUsername_TextChanged(object sender, EventArgs e)
    {
        BOUsers bo = new BOUsers();
        Users us = new Users();
        DataTable dt = bo.Load_Users(us).Tables[0];
        Label1.Text = "";
        Session["a"] = null;
        txtPassword.Focus();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (txtUsername.Text.Trim() == dt.Rows[i][1].ToString())
            {
                Session["a"] = 1;
                Label1.Text = "Username already exits";
            }
                
        }
    }
}